// 基于准备好的dom，初始化echarts实例
let man_number_rank = echarts.init(document.getElementById('man_number_rank'));
let woman_number_rank = echarts.init(document.getElementById('woman_number_rank'));
let man_rate_rank = echarts.init(document.getElementById('man_rate_rank'));
let woman_rate_rank = echarts.init(document.getElementById('woman_rate_rank'));
let total_number_rank = echarts.init(document.getElementById('total_number_rank'));

let man_number_rank_option = {
    title: {
        text: '男生人数排行'
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        type: 'category',
        data: null,
        axisLabel: {
            interval: 0,
            rotate: 30
        },
    },
    series: [{
        data: null,
        type: 'bar',
        label: {
            show: true,
            position: 'right'
        }
    }]
};
let woman_number_rank_option = {
    title: {
        text: '女生人数排行'
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        type: 'category',
        data: null,
        axisLabel: {
            interval: 0,
            rotate: 30
        },
    },
    series: [{
        data: null,
        type: 'bar',
        label: {
            show: true,
            position: 'right'
        }
    }]
};
let man_rate_rank_option = {
    title: {
        text: '男生比例排行（百分制）'
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        type: 'category',
        data: null,
        axisLabel: {
            interval: 0,
            rotate: 30
        },
    },
    series: [{
        data: null,
        type: 'bar',
        label: {
            show: true,
            position: 'right'
        }
    }]
};
let woman_rate_rank_option = {
    title: {
        text: '女生比例排行（百分制）'
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        type: 'category',
        data: null,
        axisLabel: {
            interval: 0,
            rotate: 30
        },
    },
    series: [{
        data: null,
        type: 'bar',
        label: {
            show: true,
            position: 'right'
        }
    }]
};
let total_number_rank_option = {
    title: {
        text: '总人数排行'
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        type: 'category',
        data: null,
        axisLabel: {
            interval: 0,
            rotate: 30
        },
    },
    series: [{
        data: null,
        type: 'bar',
        label: {
            show: true,
            position: 'right'
        }
    }]
};

$.ajax({
    type: "GET",
    url: '/schoolRank/menNumRank',
    success: function (res) {
        let shools = new Array();
        let num = new Array();
        for (let i = 0; i < res.length; i++) {
            shools.push(res[i].schoolName);
            num.push(res[i].menNum);
        }
        man_number_rank_option.yAxis.data = shools;
        man_number_rank_option.series[0].data = num;
        man_number_rank.setOption(man_number_rank_option);
    },
    cache: false
});
$.ajax({
    type: "GET",
    url: '/schoolRank/femaleNumRank',
    success: function (res) {
        let shools = new Array();
        let num = new Array();
        for (let i = 0; i < res.length; i++) {
            shools.push(res[i].schoolName);
            num.push(res[i].femaleNum);
        }
        woman_number_rank_option.yAxis.data = shools;
        woman_number_rank_option.series[0].data = num;
        woman_number_rank.setOption(woman_number_rank_option);
    },
    cache: false
});
$.ajax({
    type: "GET",
    url: '/schoolRank/menRateRank',
    success: function (res) {
        let shools = new Array();
        let num = new Array();
        for (let i = 0; i < res.length; i++) {
            shools.push(res[i].schoolName);
            num.push(res[i].menRate);
        }
        man_rate_rank_option.yAxis.data = shools;
        man_rate_rank_option.series[0].data = num;
        man_rate_rank.setOption(man_rate_rank_option);
    },
    cache: false
});
$.ajax({
    type: "GET",
    url: '/schoolRank/femaleRateRank',
    success: function (res) {
        let shools = new Array();
        let num = new Array();
        for (let i = 0; i < res.length; i++) {
            shools.push(res[i].schoolName);
            num.push(res[i].femaleRate);
        }
        woman_rate_rank_option.yAxis.data = shools;
        woman_rate_rank_option.series[0].data = num;
        woman_rate_rank.setOption(woman_rate_rank_option);
    },
    cache: false
});
$.ajax({
    type: "GET",
    url: '/schoolRank/totalNumRank',
    success: function (res) {
        let shools = new Array();
        let num = new Array();
        for (let i = 0; i < res.length; i++) {
            shools.push(res[i].schoolName);
            num.push(res[i].totalNum);
        }
        total_number_rank_option.yAxis.data = shools;
        total_number_rank_option.series[0].data = num;
        total_number_rank.setOption(total_number_rank_option);
    },
    cache: false
});